@echo off
TITLE Project Server - 14_hcpp_ysy
color 0A

:: Set UTF-8 encoding
chcp 65001 >nul
cls

echo ===========================================
echo          PROJECT START TOOL              
echo ===========================================
echo This script will start the server and open browser

:: Change to script directory
echo.
echo [1/4] Changing to project directory...
cd /d "%~dp0"
echo Current directory: %CD%

:: Check Node.js environment
echo.
echo [2/4] Checking Node.js environment...
node -v >nul 2>&1
if %errorlevel% neq 0 (
    echo ERROR: Node.js not found
    echo Please install Node.js first
    echo Press any key to exit...
    pause >nul
    exit /b 1
) else (
    echo Node.js found:
    node -v
    npm -v
)

:: Start server
echo.
echo [3/4] Starting server...
echo Running: node server.js
echo NOTE: This window must remain open to keep the server running
echo To stop the server, press Ctrl+C

:: Start the server
node server.js

:: This part usually won't execute as the server runs continuously
:EXIT
cls
echo ===========================================
echo Server stopped
if %errorlevel% neq 0 (
    echo ERROR: Server failed to start
    echo Check Node.js environment and dependencies
    echo Try running manually:
    echo npm install
    echo node server.js
    echo.
    pause
) else (
    echo Server closed normally
)

echo Press any key to exit...
pause >nul